home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 16051 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.3 KB

  1. Path: news.cyberport.com!usenet
  2. From: tangent@cyberport.com (Warren Young)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: The STL and nested structures
  5. Date: Tue, 09 Apr 1996 09:02:09 GMT
  6. Organization: none
  7. Message-ID: <316a26d7.2989288@news.cyberport.com>
  8. References: <4ju9q7$fa1$1@mhadg.production.compuserve.com>
  9. NNTP-Posting-Host: ppp5.cyberport.com
  10. X-Newsreader: Forte Agent .99d/32.182
  11.  
  12. Alan Huff <74312.2300@CompuServe.COM> wrote:
  13.  
  14. >I am having a problem using the STL with structures defined within 
  15. >a class definition.  Consider the following code fragment.
  16. >
  17. >>#include <vector.h>
  18. >>class Bar {
  19. >>   struct Foo {
  20. >>      int   value;
  21. >>   };
  22. >>
  23. >>   vector< Foo > fooContainer;
  24. >>}
  25. >
  26. >The compiler I am using (VC 4.1) refuses to compile.  An error is 
  27. >generated the says "'Foo' : undeclared identifier" at line 75 in 
  28. >vector.h.
  29.  
  30. It _is_ undeclared, just as a variable local to a function foo() is
  31. undeclared in a function bar().  What you want to say is:
  32.  
  33. vector<Bar::Foo> fooContainer;
  34.  
  35. Even this won't work until Foo is placed in the public section of the
  36. class (as shown above, it's in the private (default) section).
  37.  
  38. I suspect that you're an ex-C programmer, because C treated nested
  39. structures as having the same scope.  Not so in C++, and the language
  40. is better for it, IMO.
  41.  
  42. = Warren --
  43.